//
//  SectionView.m
//  Marketing
//
//  Created by Hanen 3G 01 on 16/3/31.
//  Copyright © 2016年 Hanen 3G 01. All rights reserved.
//

#import "SectionView.h"


@interface SectionView ()
{
    UIView  *backView;
}
@end

@implementation SectionView

- (id)initWithFrame:(CGRect)frame withIndex:(NSInteger)index
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubviewsWithIndex:index withFrame:frame];
        
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}
- (void)addSubviewsWithIndex:(NSInteger)index withFrame:(CGRect)frame
{
    if(index != 0){
        backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KSCreenW, 17.0f)];
        backView.backgroundColor = graySectionColor;
        backView.layer.borderColor = grayLineColor.CGColor;
        backView.layer.borderWidth = 1;
        [self addSubview:backView];
//        
//        UIView *line1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KSCreenW, 1)];
//        line1.backgroundColor = grayLineColor;
//        UIView *line2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KSCreenW, backView.height - 1)];
//        line2.backgroundColor = grayLineColor;
//        
//        [backView addSubview:line2];
//        [backView addSubview:line1];
    }
    _visit = [[UILabel alloc] initWithFrame:CGRectMake1(15, backView.maxY + 7, 130, 15)];
    //        _visit.backgroundColor = [UIColor redColor];
    _reportOne = [[UILabel alloc] initWithFrame:CGRectMake1(15, backView.maxY +25, 80, 15)];
    //         _reportOne.backgroundColor = [UIColor redColor];
    _reportOne.textColor = grayFontColor;
    [_reportOne setFont:[UIView getFontWithSize:12.0]];
    
    _reportOneNum = [[UILabel alloc] initWithFrame:CGRectMake1(95, backView.maxY +25, 30, 15)];
    //        _reportOneNum.backgroundColor = darkOrangeColor;
    _reportOneNum.textColor = grayFontColor;
    [_reportOneNum setFont:[UIView getFontWithSize:12.0]];
    
    _reportTwo = [[UILabel alloc] initWithFrame:CGRectMake1(15, backView.maxY + 40, 80, 15)];
    //        _reportTwo.backgroundColor = cyanFontColor;
    _reportTwo.textColor = grayFontColor;
    
    [_reportTwo setFont:[UIView getFontWithSize:12.0]];
    _reportTwoNum = [[UILabel alloc] initWithFrame:CGRectMake1(95, backView.maxY + 40, 50, 15)];
    //        _reportTwoNum.backgroundColor = cyanFontColor;
    _reportTwoNum.textColor = grayFontColor;
    _reportTwoNum.font = [UIView getFontWithSize:12.0];
    
    _Num = [[UILabel alloc] initWithFrame:CGRectMake(KSCreenW - 15 - 120, backView.maxY + [UIView getWidth:8.0f], 100.0f, 30.0f)];//30 是这个之前设定的左右空隙......
    _Num.textAlignment = NSTextAlignmentRight;
    _Num.font = [UIView getFontWithSize:30.0f];
    
    _arrowView = [[UIImageView alloc] initWithFrame:CGRectMake(_Num.maxX + 10, _Num.maxY - 8 * 52 / 12 + 5, 8, 8 * 52 / 12 - 8)];
//    self.arrowView.image = [UIImage imageNamed:@"箭头"];
    [self addSubview:_arrowView];
    
    //        _Num.backgroundColor = [UIColor blueColor];
    _NumBottom = [[UILabel alloc] initWithFrame:CGRectMake(KSCreenW - 15 - 100, _Num.maxY + [UIView getWidth:8.0f], 100, 15)];
    _NumBottom.textAlignment = NSTextAlignmentRight;
    _NumBottom.textColor = grayFontColor;
    //        _NumBottom.backgroundColor = cyanFontColor;
    [_NumBottom setFont:[UIView getFontWithSize:12]];
    
  
    
    _btn = [[UIButton alloc] initWithFrame:CGRectMake(0, backView.maxY +0, self.width, self.height)];
 
    [_btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    _btn.tag = 51 + index;
//    NSLog(@"按钮的tag值%d",_btn.tag);
    _btn.selected = NO;
    
    [self addSubview:_visit];
    [self addSubview:_reportOne];
    [self addSubview:_reportOneNum];
    [self addSubview:_reportTwo];
    [self addSubview:_reportTwoNum];
    [self addSubview:_Num];
    [self addSubview:_NumBottom];
//    [self addSubview:lineV];
    [self addSubview:_btn];
    
    if(index == 2){
        [self addSubview:[ViewTool getLineViewWith:CGRectMake(0, frame.size.height + 1 + backView.height, KSCreenW, 1) withBackgroudColor:grayLineColor]];
    }
}

- (void)clickBtn:(UIButton * )btn
{
    if ([self.delegate respondsToSelector:@selector(addBtnwithIndex:)]) {
        [self.delegate addBtnwithIndex:btn];
    }
}
- (void)setIsUp:(int)isUp
{
    _isUp = isUp;
    if (isUp == 1) {
//        CGAffineTransform transfrom =  CGAffineTransformMakeRotation(M_PI);
//        self.arrowView.transform = transfrom;
        
        self.arrowView.image = [UIImage imageNamed:@"HY_list_icon_arrow_rise"];
    }else{
        self.arrowView.image = [UIImage imageNamed:@"HY_list_icon_arrow_fall"];
    }
}
CG_INLINE CGRect
CGRectMake1(CGFloat x,CGFloat y,CGFloat width,CGFloat height)
{
    //创建appDelegate 在这不会产生类的对象,(不存在引起循环引用的问题)
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    //计算返回
    return CGRectMake(x * app.autoSizeScaleX, y * app.autoSizeScaleY, width * app.autoSizeScaleX, height * app.autoSizeScaleY);
}
@end
